<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of tocart
 *
 * @author Dmitry
 */
class Controller_Cart extends Controller_Action {
    //put your code here
    function index()
    {
        foreach ($_SESSION['cart'] as $num => $id)
        {
            
                $cart[$num] = $id ;
   
        }
        if(isset ($cart))
        {
            $this->registry->get('view')->set('inCart', $cart) ;
        }
        
        $this->registry->get('view')->show('cart') ;
    }
    
    function add($id)
    {
        $this->registry->get('view')->set('id', $id) ;
        $this->registry->get('view')->show('tocart') ;
    }
    
    function del($id)
    {
        $_SESSION['cart']['count']-- ;
        unset ($_SESSION['cart'][$id]) ;
        
        header("Location: /$this->path" . "cart") ;
    }
    
    function order()
    {
        foreach ($_SESSION['cart'] as $num => $id)
        {
            
                $cart[$num] = $id ;
   
        }
        if(isset ($cart))
        {
            $this->registry->get('view')->set('inCart', $cart) ;
        }
        
        $this->registry->get('view')->show('order') ;
    }
}

?>
